<hr/>
<div class="row-fluid">
    <div class="span12">
        <button class="btn btn-success" id="btn_save">保存</button>
        <a href="${request.contextPath}/product/specList" class="btn btn-info" id="btn_back">返回列表</a>
        <div class="widget-box">
            <div class="widget-title"> <span class="icon"> <i class="icon-pencil"></i> </span>
                <h5>品牌信息</h5>
            </div>
            <div class="widget-content nopadding">
                <form class="form-horizontal" method="post" action="${request.contextPath}/product/saveSpec" name="spec_form" id="spec_form">
                    <input type="hidden" name="specId" value="${spec.productSpecId}" />
                    <div class="control-group">
                        <label class="control-label">规格名称：</label>
                        <div class="controls">
                            <input type="text" name="specName" value="${spec.specName}">
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label">规格属性：</label>
                        <div class="controls">
                            <select id="specValue" name="specValue" multiple></select>
                        </div>
                    </div>
                    <!--<div class="control-group">-->
                    <!--<label class="control-label"></label>-->
                    <!--<div class="controls">-->
                    <!--<input type="submit" value="保存" class="btn btn-success">-->
                    <!--<input type="reset" value="重置" class="btn btn-danger" >-->
                    <!--</div>-->
                    <!--</div>-->
                </form>
            </div>
        </div>
    </div>
</div>
<script src="${request.contextPath}/js/jquery-1.12.2.min.js"></script>
<script src="${request.contextPath}/js/jquery.validate.js"></script>
<script src="${request.contextPath}/js/sweetalert.min.js"></script>
<script src="${request.contextPath}/js/select2.full.min.js"></script>
<script type="text/javascript">
    $(function(){

        $("#btn_back").click(function(){
            loadPage($(this).attr("href"));
            return false;
        });

        $("#btn_save").click(function(){
            $("#spec_form").submit();
        });

        var specValue = "${spec.specValues}";
        var specList = new Array();
        if (specValue.length > 0){
            var list = specValue.split(",");
            $.each(list, function(i, n){
                $("#specValue").append("<option value='" + list[i] + "' selected>" + list[i] + "</option>");
            });
        }
        $("#specValue").select2({
            tags: true
        });

        $("#spec_form").validate({
            submitHandler: function(form){
                $.ajax({
                    url: $(form).attr("action"),
                    type: "post",
                    data: $(form).serialize(),
                    success: function(result){
                        swal({
                            title: "信息提示",
                            text: result.status == "success" ? "恭喜，操作已完成！" : "很遗憾，操作失败了！",
                            type: result.status,
                            animation: "slide-from-top"
                        }, function(){
                            if (result.status == "success"){
                                loadPage("${request.contextPath}/product/specList");
                            }
                        });
                    }
                });
            },
            rules: {
                specName: {
                    "required": true
                }
            },
            errorClass: "help-inline",
            errorElement: "span",
            highlight:function(element, errorClass, validClass) {
                $(element).parents('.control-group').addClass('error');
            },
            unhighlight: function(element, errorClass, validClass) {
                $(element).parents('.control-group').removeClass('error');
                $(element).parents('.control-group').addClass('success');
            }

        });
    })
</script>